<template>
  <div class="app-container">

    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="名称" prop="befinitionKey">
        <el-input ref="input" v-model="queryParams.befinitionKey" placeholder="请输入名称" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="tastList">
      <!--      <el-table-column label="流程ID" align="center" prop="id"/>-->
      <el-table-column label="流程名称" align="center" prop="vars.definition_name" />
      <el-table-column label="任务节点名称" align="center" prop="activityName" />
       <el-table-column label="编号" align="center" prop="vars.code" />
      <el-table-column label="标题" align="center" prop="vars.title" />
      <el-table-column label="备注" align="center" prop="vars.remark" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
       <el-table-column label="任务id" align="center" prop="taskId" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="examineAndApprove (scope.row)" v-hasPermi="['workflow:leave:edit']">审批
          </el-button>

          <el-button size="mini" type="text" icon="el-icon-edit" @click="historicActivity (scope.row)" v-hasPermi="['workflow:leave:edit']">追溯
          </el-button>

        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />


    <!-- 添加或修改流程对话框 详情页-->
    <el-dialog :title="detailDialog.title" :visible.sync="detailDialog.open" width="700px" append-to-body>

      <component v-bind:is="componentName" :detailDialog.sync="detailDialog" @doRefresh="getList"> </component>

      <pocesComplete v-if="detailDialog.hasComplete" :detailDialog.sync="detailDialog" @doRefresh="getList"></pocesComplete>
    </el-dialog>

    <el-dialog :title="historicDialog.title" :visible.sync="historicDialog.open" width="1000px" append-to-body>
      <div class="chart-wrapper">
        <pocessHistoric :detailDialog.sync="historicDialog">
        </pocessHistoric>
      </div>
    </el-dialog>




  </div>
</template>

<script>
  /* import pocessUpdate from "../pocess/pocessUpdate.vue"; */

  import pocesComplete from "@/views/activiti/pocess/pocesComplete.vue";
  import pocessHistoric from "@/views/activiti/pocess/pocessHistoric.vue";


  import {
    listTask,
    formDataShow,
    formDataSave
  } from "@/api/activiti/task";

  export default {
    name: "Leave",
    components: {
      'my-component': () => import('../pocess/pocessItem.vue'),
      'my-component2': () => import('../pocess/pocessItem2.vue'),
      'LosseventDetail': () => import('@/views/grc/lossevent/LosseventDetailTabs.vue'),

      pocessHistoric,
      pocesComplete,
    },
    data() {
      return {
        componentName: "my-component",
        defComponentName: "my-component",

        id: '',
        definitionKey: '',
        businessKey: '',
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 请假表格数据
        tastList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          befinitionKey: "",
        },
        // 表单参数
        form: {
          formData: []
        },


        // 弹出层标题
        detailDialog: {

          //弹框标题
          title: "",
          //业务
          id: "",

          // 业务id
          businessId: "",
          //任务id
          taskId: "",
          open: false,
          //是否是详情页 true：是
          isDisabled: true,



          //工作流控制
          //是否存在工作流启动页面
          hasPoces: false,

          //是否工作流提交页面
          hasComplete: false,

          befinitionKey: "lossevent_6",
          vars: {
            acti_num: 4,
            title: "工作流标题"
          },
        },

        historicDialog: {
          id: "",
          title: "",
          open: false,
        },

        // 表单校验
        rules: {}
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },

      /** 查询请假列表 */
      getList() {
        this.loading = true;
        listTask(this.queryParams).then(response => {
          this.tastList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },




      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.definitionKey = '',
          this.businessKey = '',
          this.form = {
            formData: [],
          };
        this.resetForm("form");
      },

      /** 历史 */
      historicActivity(row) {



        const proInstanceId = row.proInstanceId


        this.historicDialog.open = true;
        this.historicDialog.title = "流程追溯";
        this.historicDialog.id = proInstanceId;


      },

      /** 审批按钮操作 */
      examineAndApprove(row) {
        console.log("父页面业务id:" + row.vars.businessId)
        console.log("父页面task:" + row.taskId)

        const businessId = row.vars.businessId
        const taskId = row.taskId;

        const componentName = row.vars.componentName
        if (componentName) {
          this.componentName = componentName
        } else {
          this.componentName = this.defComponentName
        }

        this.detailDialog.id = businessId
        this.detailDialog.taskId = taskId

        this.detailDialog.open = true;
        this.detailDialog.isDisabled = true;
        this.detailDialog.hasPoces = false;
        this.detailDialog.hasComplete = true;
        this.detailDialog.title = "提交审批流程";
      },

    }
  };
</script>
